﻿Imports Mystery

Public Class ReadOnlyMoneyView
    Implements IPropertyControl

    Private _property_info As System.Reflection.PropertyInfo
    Private _content_property As ContentProperty


    Public Property property_info As System.Reflection.PropertyInfo Implements IPropertyControl.property_info
        Get
            Return _property_info
        End Get
        Set(value As System.Reflection.PropertyInfo)
            _content_property = value.getMysteryAttribute(Of ContentProperty)()
            _label = _content_property.label
            _property_info = value
        End Set
    End Property


    Public Property value As Object Implements IPropertyControl.value
        Get
            Return typed_value
        End Get
        Set(value As Object)
            If TypeOf (value) Is ContentPropertyValue Then value = DirectCast(value, ContentPropertyValue).getValue
            Dim new_value As Double = value
            Me.Dispatcher.Invoke(Sub() tbValue.Text = new_value)
        End Set
    End Property


    Private _content As IContent

    Public Property content_item As Mystery.IContent Implements IPropertyControl.content
        Get
            Return _content
        End Get
        Set(value As Mystery.IContent)
            _content = value
            Me.value = _content_property.retrive()(_content)
        End Set
    End Property

    Public Property typed_value As Double
        Get
            If String.IsNullOrEmpty(tbValue.Text) Then Return 0
            Return CDbl(tbValue.Text)
        End Get
        Set(value As Double)
            Me.value = value
        End Set
    End Property

    Private _label As String
    Public ReadOnly Property label As String Implements IPropertyControl.label
        Get
            Return _label
        End Get
    End Property


    Public ReadOnly Property wished_height As System.Windows.GridLength Implements IPropertyControl.wished_height
        Get
            Return GridLength.Auto
        End Get
    End Property

    Public Function setInContent() As IEnumerable(Of IContent) Implements IPropertyControl.setInContent
        'read only we sayed
        Return New List(Of IContent)
    End Function

    

    Public Event valueChanged() Implements IPropertyControl.valueChanged

    
End Class
